package com.gitee.hermer.engine.jars.starter.thread.pool;

import java.util.concurrent.Callable;
import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.RecursiveTask;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

import com.gitee.hermer.engine.jars.dependent.dsm.IEnginePropertiesAware;
import com.gitee.hermer.engine.jars.starter.thread.pool.callback.CallableResult;
import com.gitee.hermer.engine.jars.starter.thread.pool.config.ThreadPoolProperties;

public interface IThreadPoolManage extends DisposableBean,InitializingBean,IEnginePropertiesAware<ThreadPoolProperties>{

	/**
	 * 同步执行，支持子线程拆分执行(有返回)
	 * @param task
	 * @return
	 */
	public <T extends RecursiveTask<V>,V> V  execute(T task);
	/**
	 * 同步执行(有返回)
	 * @param task
	 * @param resultClass
	 * @return
	 */
	public <T extends Callable<V>,V> V  execute(T task);
	/**
	 * 同步执行(无返回)
	 * @param task
	 * @param resultClass
	 * @return
	 */
	public <T extends Runnable> void execute(T task);

	
	public <T extends ForkJoinTask<V>,V> ForkJoinTask<V>  executeAsyn(T task) throws Exception;
	/**
	 * 异步执行(无返回)
	 * @param task
	 * @param resultClass
	 * @return
	 */
	public <T extends Runnable> ForkJoinTask<?>  executeAsyn(T task) throws Exception;
	/**
	 * 异步执行(有返回)
	 * @param task
	 * @param resultClass
	 * @return
	 */
	public <T extends Callable<V>,V> ForkJoinTask<V>  executeAsyn(T task) throws Exception;
	/**
	 * 异步执行，支持子线程拆分执行(有返回)
	 * @param task
	 * @param resultClass
	 * @return
	 */
	public <T extends RecursiveTask<V>,V> ForkJoinTask<V> executeAsyn(T task) throws Exception;
	
	
	/**
	 * 异步执行(有返回) 默认超时时间(60s)
	 * @param task
	 * @param call
	 * @throws Exception
	 */
	public <T extends ForkJoinTask<V>,V> void executeAsyn(T task,CallableResult<V> call) throws Exception;
	/**
	 * 异步执行(有返回) 默认超时时间(60s)
	 * @param task
	 * @param resultClass
	 * @return
	 */
	public <T extends Callable<V>,V> void executeAsyn(T task,CallableResult<V> call) throws Exception;
	/**
	 * 异步执行，支持子线程拆分执行(有返回) 默认超时时间(60s)
	 * @param task
	 * @param resultClass
	 * @return
	 */
	public <T extends RecursiveTask<V>,V> void executeAsyn(T task,CallableResult<V> call) throws Exception;
	
	public Integer getExecuteTimeOut();


}
